﻿#region 信息

// Copyright©2014 Rex Rao all rights reserved.
// File name : SoMcCoffee\Sohobloo.SoCommon\LoggableExtension.cs
// Author : Sohobloo
// Create time : 2014/02/07 9:07
// Update time : 2014/02/08 10:41

#endregion

#region 引用

using System;
using Sohobloo.SoCommon.CommonExtension;

#endregion

namespace Sohobloo.SoCommon.Log
{
    public static class LoggableExtension
    {
        public static void LogInfo(this ILoggable loggerHolder, object message)
        {
            CheckLogger(loggerHolder);
            loggerHolder.Logger.Info(message);
        }

        public static void LogError(this ILoggable loggerHolder, object message)
        {
            CheckLogger(loggerHolder);
            loggerHolder.Logger.Error(message);
        }

        public static void LogError(this ILoggable loggerHolder, Exception ex)
        {
            CheckLogger(loggerHolder);
            loggerHolder.Logger.Error(ex);
        }

        public static void LogError(this ILoggable loggerHolder, object message, Exception ex)
        {
            CheckLogger(loggerHolder);
            loggerHolder.Logger.Error(message, ex);
        }

        public static void LogDebug(this ILoggable loggerHolder, object message)
        {
            CheckLogger(loggerHolder);
            loggerHolder.Logger.Debug(message);
        }

        public static void TraceSql(this ILoggable loggerHolder, object message)
        {
            ArgumentHelper.Instance.CheckNull(loggerHolder);
            if(loggerHolder.Logger.IsNotNull())
            {
                loggerHolder.Logger.TraceSql(message);
            }
        }

        private static void CheckLogger(ILoggable loggerHolder)
        {
            ArgumentHelper.Instance
                          .CheckNull(loggerHolder)
                          .CheckNull(loggerHolder.Logger);
        }
    }
}